package com.gryffonx.Interfaces.dice;

import com.gryffonx.DiceRoller.StaticDiceRoller;

import javax.swing.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;


/**
 * @author Erik Stell
 * @version 1.0
 */
public class DiceRoller {
    private JSpinner d4Spinner2;
    private JSpinner d4Spinner1;
    private JLabel PerRoll1;
    private JButton btnRollD4;
    private JTextField d4ResultText;
    private JPanel d4Panel;
    private JRadioButton d4rdoNo;
    private JRadioButton d4rdoYes;
    private JPanel mainPanel;
    private JSpinner spinner1;
    private JLabel diceRollerName;
    private JSpinner spnr_sides;

    public JSpinner getSpinner1() {
        return spinner1;
    }

    public void setSpinner1(JSpinner spinner1) {
        this.spinner1 = spinner1;
    }

    public JLabel getDiceRollerName() {
        return diceRollerName;
    }

    public void setDiceRollerName(JLabel diceRollerName) {
        this.diceRollerName = diceRollerName;
    }

    void setDiceRollerNameLabelValue(String newVal) {
        this.diceRollerName.setText(newVal);
    }

    public DiceRoller(String title) {
        setDiceRollerNameLabelValue(title);

        d4Spinner1.setValue(1);
        btnRollD4.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent evt) {
                try {
                    //create an int out of the modifier field
                    int mod = 1;

                    int sides = 6;

                    if (sides <= 0) {
                        sides = 6;
                    }

                    //create an int out of the number of rolls field
                    int numRolls = 1;

                    if (numRolls <= 0) {
                        numRolls = 1;
                    }

                    //roll the dice
                    int roll = StaticDiceRoller.rolldSomething(sides, numRolls);

                    //add the modifier
                    int adjRoll = roll + mod;

                    d4ResultText.setText(Integer.toString(adjRoll));
                } catch (Exception e) {
                    d4ResultText.setText("error!");
                }
            }
        });
    }

    public JSpinner getD4Spinner2() {
        return d4Spinner2;
    }

    public void setD4Spinner2(JSpinner d4Spinner2) {
        this.d4Spinner2 = d4Spinner2;
    }

    public JSpinner getD4Spinner1() {
        return d4Spinner1;
    }

    public void setD4Spinner1(JSpinner d4Spinner1) {
        this.d4Spinner1 = d4Spinner1;
    }


    public JLabel getPerRoll1() {
        return PerRoll1;
    }

    public void setPerRoll1(JLabel perRoll1) {
        PerRoll1 = perRoll1;
    }

    public JButton getBtnRollD4() {
        return btnRollD4;
    }

    public void setBtnRollD4(JButton btnRollD4) {
        this.btnRollD4 = btnRollD4;
    }

    public JTextField getD4ResultText() {
        return d4ResultText;
    }

    public void setD4ResultText(JTextField d4ResultText) {
        this.d4ResultText = d4ResultText;
    }

    public JPanel getD4Panel() {
        return d4Panel;
    }

    public void setD4Panel(JPanel d4Panel) {
        this.d4Panel = d4Panel;
    }

    public JRadioButton getD4rdoNo() {
        return d4rdoNo;
    }

    public void setD4rdoNo(JRadioButton d4rdoNo) {
        this.d4rdoNo = d4rdoNo;
    }

    public JRadioButton getD4rdoYes() {
        return d4rdoYes;
    }

    public void setD4rdoYes(JRadioButton d4rdoYes) {
        this.d4rdoYes = d4rdoYes;
    }

    public JPanel getMainPanel() {
        return mainPanel;
    }

    public void setMainPanel(JPanel mainPanel) {
        this.mainPanel = mainPanel;
    }
}
